package 链表;

public abstract class AbstractList<E> implements List<E>{
	protected int size;
	// 1.数组的大小
	public int size() {
		return size;
	}
	// 2.数组是否为空
	public boolean isEmpty() {
		return size == 0;
	}
	
	// 4. 是否包含某个元素
	public boolean contains(E element) {
		return indexOf(element) != ELEMENT_NOT_FOUND;
	}
	
	// 8. 添加元素到尾部
	public void add(E element) {
		add(size, element);
	}
	
	protected void outOfBounds(int index) {
		throw new IndexOutOfBoundsException("index = "+ index+ ", size = "+ size); 
	}
	
	protected void rangeCheck(int index) {
		if(index < 0 || index >= size) {
			outOfBounds(index);
		}
	}
	
	protected void rangeCheckForAdd(int index) {
		if (index < 0 || index > size) {
			outOfBounds(index);
		}
	}
}
